package com.easy.framework.common.exception;


public class BaseException extends RuntimeException {
    private static final long serialVersionUID = 1L;
    private int code = 400;
    public static final ExceptionType DEFAULT_EXCEPTION;

    public int getCode() {
        return this.baseCode() + this.code;
    }

    public BaseException() {
        this(DEFAULT_EXCEPTION);
    }

    public BaseException(String message) {
        this(DEFAULT_EXCEPTION.getCode(), message);
    }

    public BaseException(ExceptionType exceptionType) {
        this(exceptionType.getCode(), exceptionType.getMessage());
    }

    public BaseException(int code, String message) {
        super(message);
        this.code = code;
    }

    public int baseCode() {
        return 0;
    }

    static {
        DEFAULT_EXCEPTION = ExceptionType.DEFAULT_EXCEPTION;
    }

    public static enum ExceptionType {
        DEFAULT_EXCEPTION(400, "UNKNOWN"),
        NOT_FOUND(404, "NOT FOUND");

        private int code;
        private String message;

        public int getCode() {
            return this.code;
        }

        public String getMessage() {
            return this.message;
        }

        private ExceptionType(int code, String message) {
            this.code = code;
            this.message = message;
        }
    }
}
